﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using MVVM.ViewModel;
using System.ComponentModel;

namespace MVVM.WPFView {
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application,INavigationActions,INotifyPropertyChanged {
        #region INavigationActions Members

        private Window currentWindow = null;

        public void OpenCustomersView() {
            CustomersView customersView = new CustomersView();
            currentWindow = customersView;
            customersView.Show();
        }

        public void OpenCustomerView() {
            CustomerView customerView = new CustomerView();
            DataContext = null;
            currentWindow = customerView;
            customerView.Show();
        }

        public void OpenCustomerView(object context) {
            CustomerView customerView = new CustomerView();
            DataContext = context;
            currentWindow = customerView;
            customerView.Show();
        }

        public void OpenOrdersView() {

        }

        public void OpenOrderView() {

        }

        public void CloseCurrentView() {
            currentWindow.Close();
        }

        public void CloseApplication() {
            Application.Current.Shutdown();
        }

        public bool QueryConfirmation(string title, string message) {
            return MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
        }

        public void ShowError(string title, string message) {
            MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Error);
        }

        void CloseForm(Window windowName) {
            if (currentWindow.GetType().Equals(currentWindow)) {
                currentWindow.Close();
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName) {
            OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

        protected void OnPropertyChanged(PropertyChangedEventArgs e) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, e);
        }

        #endregion


        #region INavigationActions Members


        public object DataContext {
            get;
            set;
        }

        #endregion
    }
}
